package com.dronff.controller;

import com.dronff.common.ResponseResult;
import com.dronff.common.feign.OrdersFeign;
import com.dronff.mapper.OrdersMapper;
import com.dronff.pojo.Orders;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;

/**
 * @author tyf
 * @date 2022/7/21 18:16
 */
@RestController
public class OrdersController implements OrdersFeign {
    @Resource
    OrdersMapper ordersMapper;
    @GlobalTransactional
    @Override
    public ResponseResult creOrder(Integer id, Integer money) {
        Orders order = new Orders(1, money, LocalDateTime.now().toString().replace("T", " ").substring(0,19), id);
        if(ordersMapper.insert(order)==1){
            return new ResponseResult(200,"订单添加成功，id为:"+order.getId());
        }
        return new ResponseResult(500,"订单添加失败");
    }
}
